/**
 * customerdepartment控制器
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.controller;


import com.sxf.crm.entity.Department;
import com.sxf.crm.service.DepartmentService;

import lombok.RequiredArgsConstructor;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/customer-departments")
@RequiredArgsConstructor
public class CustomerDepartmentController {

    private final DepartmentService departmentService;

    @GetMapping
    @PreAuthorize("hasAuthority('customer:view')")
    public ResponseEntity<List<Department>> getAllDepartments(@RequestParam(required = false) String name) {
        List<Department> departments = departmentService.getAllDepartments(name);
        return ResponseEntity.ok(departments);
    }
} 